package com.aigis.big4.tmp.javase.collection.map;

import java.util.*;

public class HashtableTest {
    public static void main(String[] args){
        //------------------------测试hashmap的相等的情况，key的hashcode和equals相等，则是同一个可以, 对于vaule相等的判断则为equals相等即可--------------------------------------
        Hashtable hashtable=new Hashtable();
        hashtable.put(new A(6000),"java");
        hashtable.put(new A(8000),"python");
       // hashtable.put(new A(1000),new B());

//        System.out.println(hashtable);
//        System.out.println(hashtable.contains("c++"));
//        System.out.println(hashtable.containsKey(new A(8000)));
//        System.out.println(hashtable.remove(new A(8000)));
//        System.out.println(hashtable);



        //-------------------------HasMap默认排序-------------------
        System.out.println("--------HasMap默认排序,按照key值得字母顺序排序-------------");
        HashMap htSort=new HashMap();
        htSort.put("a","java");
        htSort.put("d","python");
        htSort.put("b","c++");
        htSort.put("c","c");
        System.out.println(htSort);


        //-------------------------HasMap不可变对象-------------------
        System.out.println("--------HasMap不可变对象-------------");
        HashMap ht=new HashMap();
        ht.put(new A(600),"java");
        ht.put(new A(800),"python");
        ht.put(new A(500),"c++");
        ht.put(new A(550),"c");
        System.out.println(ht);

        Iterator it=ht.keySet().iterator();
        A first= (A) it.next();
        first.count=700;
//        System.out.println("修改前key是否存在:"+ht.get(new A(600)));


//        System.out.println(ht.remove(new A(700)));
//        System.out.println(ht);
//        System.out.println(ht.remove(new A(600)));


        //-------------------------LinkedHasMap-------------------
        System.out.println("--------LinkedHasMap按照添加顺序排序-------------");
        LinkedHashMap lhs=new LinkedHashMap();
        lhs.put("语文",80);
        lhs.put("数学",90);
        lhs.put("英语",100);

        System.out.println(lhs);
        lhs.forEach((k,v)->System.out.println(k+":"+v));




        //-------------------------TreeMap-------------------
        System.out.println("--------TreeMap 排序,key 实现Comparable接口,重写compareTo方法,定义排序方式-------------");
        TreeMap tm=new TreeMap();
        tm.put(new R(9),"java");
        tm.put(new R(-5),"python");
        tm.put(new R(3),"c");
        System.out.println(tm);
        //下一个
        System.out.println(tm.higherEntry(new R(2)));
        //截取,参数大小不能错，因为有排序方向：升序 from 要大于 to,降序反过来
        System.out.println(tm.subMap(new R(9),new R(2)));

    }
}
